'''
Author: ironlionwgHH huanghao_bnu@163.com
Date: 2023-05-22 20:34:04
LastEditors: ironlionwgHH huanghao_bnu@163.com
LastEditTime: 2024-03-13 15:41:46
FilePath: /asteroid_orbit/src/_oel_file_process.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
'''
 _   _                                     _   _                   _          ____               _
| | | |  _   _    __ _   _ __     __ _    | | | |   __ _    ___   ( )___     / ___|   ___     __| |   ___ 
| |_| | | | | |  / _` | | '_ \   / _` |   | |_| |  / _` |  / _ \  |// __|   | |      / _ \   / _` |  / _ \
|  _  | | |_| | | (_| | | | | | | (_| |   |  _  | | (_| | | (_) |   \__ \   | |___  | (_) | | (_| | |  __/
|_| |_|  \__,_|  \__,_| |_| |_|  \__, |   |_| |_|  \__,_|  \___/    |___/    \____|  \___/   \__,_|  \___|
                                  |___/
'''
import os
import numpy as np

AU_km = 149597870.7

class oel_file():
    def __init__(self, oel_file_path: str, oel_file_name: str):
        self.oel_file_path = oel_file_path
        self.oel_file_name = oel_file_name
        self.oel_file_path_name = os.path.join(self.oel_file_path, self.oel_file_name)
        self.object_name = oel_file_name.split("_")[0]
        # 提取信息
        with open(self.oel_file_path_name, "r") as oel_file:
            oel_file_list = oel_file.readlines()
            self.oel_file_list_header = oel_file_list[:5]
            self.oel_file_list_data   = oel_file_list[5:]
            # ++++++++++++++++++++++++++++++++++++++++ 选取包含RMS信息的对应行 ++++++++++++++++++++++++++++++++++++++++
            for line in oel_file_list:
                if "RMS" in line:
                    line_RMS = line
                    self.line_RMS = line_RMS
                else:
                    pass
            
            
            
    '''
    Function :
                extract_ele_time
    Description :
                
    Edition  :  Huang Hao/2023.05.22/
    Log      :
    Input    :
    Return   :
                time_str    str     time in oel file | e.g. ' MJD     60110.000000000 TDT'
    func used:
                
    Warning  :
                
    '''
    def extract_ele_time(self) -> str:
        time_str = self.oel_file_list_data[4]
        
        return time_str
    
    
    def extract_rms_cov(self):
        split_list = self.line_RMS.split()
        rms_x = float(split_list[2])*AU_km
        rms_y = float(split_list[3])*AU_km
        rms_z = float(split_list[4])*AU_km
        rms_vx = float(split_list[5])*AU_km/86400*1e3
        rms_vy = float(split_list[6])*AU_km/86400*1e3
        rms_vz = float(split_list[7])*AU_km/86400*1e3
        
        cov = np.array([[rms_x, rms_y, rms_z, rms_vx, rms_vy, rms_vz]])
        
        return cov